﻿#pragma once

_NAMESPACE_BEGIN

///物理形状描述
struct Shape_Desc
{
	Shape_Desc()
	{			
		localPose.id();//单位化
	}

	NxMat34 localPose;
};

///立方体
struct Cube_Desc:public Shape_Desc
{
	Cube_Desc()
	{
		size=NxVec3(1,1,1);		
	}
	NxVec3 size;		
	UINT shapeFlags;
};

///球体
struct Sphere_Desc:public Shape_Desc
{
	Sphere_Desc()
	{
	}
	float radius;
	float slices;
};

///胶囊体
struct Capsule_Desc:public Shape_Desc
{
	Capsule_Desc()
	{
		radius=1;
		slices=20;
		height=4;
	}
	float radius;
	float height;
	float slices;
};

///车轮
enum NxWheelFlags 
{
	NX_WF_STEERABLE_INPUT		= (1 << 0),
	NX_WF_STEERABLE_AUTO		= (1 << 1),
	NX_WF_AFFECTED_BY_HANDBRAKE	= (1 << 2),
	NX_WF_ACCELERATED			= (1 << 3),

	NX_WF_BUILD_LOWER_HALF		= (1 << 8),
	NX_WF_USE_WHEELSHAPE		= (1 << 9),

	NX_WF_ALL_WHEEL_FLAGS		= NX_WF_STEERABLE_INPUT
	| NX_WF_STEERABLE_AUTO
	| NX_WF_AFFECTED_BY_HANDBRAKE
	| NX_WF_ACCELERATED,

};
struct Wheel_Desc:public Shape_Desc
{
	Wheel_Desc()
	{
		setToDefault();
	}
	NxVec3					position;
	NxReal					wheelRadius;
	NxReal					wheelWidth;
	NxReal					wheelSuspension;
	NxReal					springRestitution;
	NxReal					springDamping;
	NxReal					springBias;
	NxReal					maxBrakeForce;
	NxReal					frictionToSide;
	NxReal					frictionToFront;
	NxU32					wheelApproximation;
	NxU32					wheelFlags;
	void*					userData;
	void Wheel_Desc::setToDefault()
	{
		position.set(0,0,0);
		//wheelAxis.set(0,0,1);
		//downAxis.set(0,-1,0);
		userData = NULL;
		wheelFlags = 0;
		wheelRadius = 1;
		wheelWidth = 0.1f;

		springBias = 0;
		springRestitution = 1.f;
		springDamping = 0.f;

		wheelSuspension = 1.f;
		maxBrakeForce = 0.f;
		frictionToSide = 1.0f;
		frictionToFront = 1.0f;
	}
	bool isValid() const
	{
		if (wheelApproximation > 0 && wheelApproximation < 4) {
			fprintf(stderr, "wheelApproximation must be either 0 or bigger than 3\n");
			printf("wheelApproximation must be either 0 or bigger than 3\n");
			return false;
		}
		if ((wheelFlags & NX_WF_STEERABLE_AUTO) && (wheelFlags & NX_WF_STEERABLE_INPUT)) {
			fprintf(stderr, "NX_WF_STEERABLE_AUTO and NX_WF_STEERABLE_INPUT not permitted at the same time\n");
			printf("NX_WF_STEERABLE_AUTO and NX_WF_STEERABLE_INPUT not permitted at the same time\n");
			return false;
		}
		return true;
	}
};

///平面
struct Plane_Desc:public Shape_Desc
{
	Plane_Desc()
	{		    
	}
	float width;
	float length;
	NxVec3 pos;
};

///触发器
struct Trigger_Desc:public Shape_Desc
{
	Trigger_Desc()
	{
		size=NxVec3(1,1,1);
	}
	NxVec3 size;
};

_NAMESPACE_END